#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=2e6+5;
pair<int,int>Q[N];
tuple<int,int,int>E[N];
int cnt[N],sa[N],man[N],fd[N],s[N],L[N],R[N],rk[N],id[N],f[N];
inline int find(const int&x){
	return x==fd[x]?x:fd[x]=find(fd[x]);
}
template<class T>inline void sort(T* a,int n,int m){
	T* b=new T[m+1];
	fill(cnt,cnt+n+1,0);
	for(int i=1;i<=m;++i)++cnt[get<0>(a[i])];
	for(int i=1;i<=n;++i)cnt[i]+=cnt[i-1];
	for(int i=1;i<=m;++i)b[cnt[get<0>(a[i])]--]=a[i];
	copy(b+1,b+m+1,a+1);
	delete []b;
}
inline void MAIN(){
	int n=0,m=0,q=0;
	cin>>n,man[1]=1,man[n+n+1]=1;
	for(int i=1;i<=n;++i)cin>>sa[i],++sa[i];
	for(int i=2;i<=n+n;++i)cin>>man[i],++man[i];
	fill(rk+1,rk+n+2,0);
	for(int i=1;i<=n;++i)
		if(sa[i]>n||sa[i]<1||rk[sa[i]])return cout<<"-1\n",void();
		else rk[sa[i]]=i;
	iota(fd+1,fd+n+n+2,1);
	for(int i=1,j=0,k=0;i<=n+n+1;++i){
		for(int t=min(man[k+k-i],j-i+1);t<man[i];++t){
			if(i-t<1||i+t>n+n+1)return cout<<"-1\n",void();
			fd[find(i-t)]=find(i+t);
		}
		if(man[i]+i>j)j=man[i]+i-1,k=i;
	}
	for(int i=1;i<=n+n;i+=2)fd[find(i)]=find(i+2);
	for(int i=2;i<=n+n;++i)
		if(i-man[i]>=1&&i+man[i]<=n+n+1)
			if(find(i-man[i])==find(i+man[i]))return cout<<"-1\n",void();
			else Q[++q]=make_pair(find(i-man[i]),find(i+man[i]));
	for(int i=1;i<=n;++i)s[i]=find(i+i);
	for(int i=1;i<n;++i)
		if(rk[sa[i]+1]>=rk[sa[i+1]+1])
			Q[++q]=make_pair(s[sa[i]],s[sa[i+1]]);
	for(int i=1;i<=n+n;++i)L[i]=n+1,R[i]=0;
	for(int i=1;i<=n;++i)L[s[sa[i]]]=min(L[s[sa[i]]],i),R[s[sa[i]]]=max(R[s[sa[i]]],i);
	for(int i=1;i<=n+n;++i)if(L[i]<=R[i])E[++m]=make_tuple(L[i],R[i],i);
	sort(E,n,m);
	for(int i=1,R=0;i<=m;++i){
		const auto [l,r,id]=E[i];
		if(l<=R)fd[find(id)]=find(get<2>(E[i-1]));
		R=max(R,r);
	}
	for(int i=1;i<=n;++i)s[i]=find(i+i);
	fill(f+1,f+n+1,0);
	for(int i=1;i<=n;++i)if(s[sa[i-1]]!=s[sa[i]])id[s[sa[i]]]=id[s[sa[i-1]]]+1;
	for(int i=1;i<=q;++i){
		auto&[x,y]=Q[i];
		if((x=find(x))==(y=find(y)))return cout<<"-1\n",void();
		x=id[x],y=id[y];
		if(x<y)swap(x,y);
	}
	sort(Q,n,q);
	for(int i=1,R=0;i<=q;++i){
		const auto [r,l]=Q[i];
		if(l>=R)R=r,++f[r];
	}
	for(int i=1;i<=n;++i)f[i]+=f[i-1];
	if(f[n]>26)return cout<<"-1\n",void();
	for(int i=1;i<=n;++i)cout<<(char)('a'+f[id[s[i]]]);
	cout<<'\n';
}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	int t=1;cin>>t;while(t--)MAIN();
	return 0;
}
/*
*/